﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;
using System.Configuration;


namespace Core
{
    public static partial class functional
    {
        /// <summary>
        /// 将目录压缩为RAR格式
        /// </summary>
        /// <param name="patch">要压缩的目录</param>
        /// <param name="rarPatch">压缩到哪个目录</param>
        /// <param name="rarName">压缩文件名</param>
        static public void rar(string patch, string rarPatch, string rarName)
        {
            String the_rar;
            String the_Info;
            ProcessStartInfo the_StartInfo;
            Process the_Process;
            try
            {
                the_rar = ConfigurationManager.AppSettings["RAREXE"];
                if (!Directory.Exists(patch))
                {
                    return;
                }
                the_Info = " a " + rarName + " " + patch + " -r"; ;
                the_StartInfo = new ProcessStartInfo();
                the_StartInfo.FileName = the_rar;
                the_StartInfo.Arguments = the_Info;
                the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                the_StartInfo.WorkingDirectory = rarPatch;
                the_Process = new Process();
                the_Process.StartInfo = the_StartInfo;
                the_Process.Start();
                the_Process.WaitForExit();
                the_Process.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        } 
    }
}
